import logging
'''设置日志的名字'''
logger = logging.getLogger("天际汽车")
'''日志的级别'''
logger.setLevel(logging.DEBUG)
'''日志的格式'''
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s : %(message)s')

'''设置控制台输出'''
lf = logging.StreamHandler()
lf.setLevel(logging.DEBUG)
lf.setFormatter(formatter)

'''控制台处理器添加到logger中'''
logger.addHandler(lf)


'''添加打印日志的路径'''
import os
import time

path = os.path.dirname(os.path.dirname(__file__))
path_logs = os.path.join(path,'logs')
if not os.path.exists(path_logs):
    os.mkdir(path_logs)

log_path = os.path.join(path_logs,time.strftime('%Y-%m-%d')+".log")
ls = logging.FileHandler(filename=log_path,encoding='utf8')
ls.setLevel(logging.DEBUG)
ls.setFormatter(formatter)
logger.addHandler(ls)
